// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: H Block Object
// Script Author: Christan Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 55 : TYPE_HBLOCK

// Function declarations
reserve function HBlock_DebugDraw
reserve function HBlock_DebugSpawn

// Static Values
public value HBlock_value31 = 0;

// Tables

function HBlock_DebugDraw
	DrawSprite(0)
end function


function HBlock_DebugSpawn
	CreateTempObject(TypeName[H Block], object.direction, object.xpos, object.ypos)
	temp0 = object[0].value17
	temp0 -= HBlock_value31
	if temp0 == 0
		if object.direction == FLIP_NONE
			object[tempObjectPos].value0 = 0x2000
		else
			object[tempObjectPos].value0 = -0x2000
		end if
	else
		if object.direction == FLIP_NONE
			object[tempObjectPos].value0 = 0x1000
		else
			object[tempObjectPos].value0 = -0x1000
		end if
	end if
end function


event ObjectMain
	object.angle = SYZSetup_value29
	object.angle *= 512
	object.angle /= 356
	Sin(object.value2, object.angle)
	object.value2 *= object.value0
	object.value2 += object.xpos
	object.value2 &= -0x10000
	object.value2 -= object.value1
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		temp0 = object.xpos
		object.xpos = object.value1
		temp1 = object[currentPlayer].gravity
		BoxCollisionTest(C_BOX, object.entityPos, -16, -16, 16, 16, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		if checkResult == 1
			if temp1 == 1
				object[currentPlayer].xpos += object.value2
			end if
		end if
		object.xpos = temp0
	next
end event


event ObjectDraw
	Sin(object.value1, object.angle)
	object.value1 *= object.value0
	object.value1 += object.xpos
	object.value1 &= -0x10000
	DrawSpriteXY(0, object.value1, object.ypos)
end event


event ObjectStartup
	LoadSpriteSheet("SYZ/Objects.gif")
	SpriteFrame(-16, -16, 32, 32, 119, 34)
	foreach (TypeName[H Block], arrayPos0, ALL_ENTITIES)
		switch object[arrayPos0].propertyValue
		case 0
			object[arrayPos0].value0 = 0x2000
			break
		case 1
			object[arrayPos0].value0 = 0x1000
			break
		case 2
			object[arrayPos0].value0 = -0x1000
			break
		case 3
			object[arrayPos0].value0 = -0x2000
			break
		end switch
	next
	temp0 = 0
	HBlock_value31 = DebugMode_ObjCount
	while temp0 < 2
		SetTableValue(TypeName[H Block], DebugMode_ObjCount, DebugMode_TypesTable)
		SetTableValue(HBlock_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
		SetTableValue(HBlock_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
		DebugMode_ObjCount++
		temp0++
	loop
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
